package com.tjetc.input;

import org.junit.jupiter.api.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class _7InputStreamReader {

    @Test
    public void testInputStreamReader() throws IOException {
        // InputStreamReader 可以改变编码
        InputStreamReader reader =
                new InputStreamReader(new FileInputStream("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/file/hello.txt"), StandardCharsets.UTF_8);
        char[] chars = new char[64];
        int len = 0;
        while ((len = reader.read(chars)) != -1) {
            System.out.println(new String(chars, 0, len));
        }
    }


    @Test
    public void testInputStreamReader1() throws IOException {

        // InputStreamReader 可以改变编码
        InputStreamReader reader =
                new InputStreamReader(new FileInputStream("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/file/hello.txt"), StandardCharsets.UTF_8);
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line = "";
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }
    }
}
